** Data reading and variable selection from raw data
** FRENCH 1985 TRAINING AND QUALIFYING SURVEY PROFESSIONAL


** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/  

** 02. Consructing year and country variables **

ge year=1985
lab var year "survey year"

ge country=250
lab var country "ISO country code"
//France: 250 (ISO Country Codes) 


** 03. ID variables **

*ge pid=no
ge pid=_n
lab var pid "person id"

** destring variables

destring se ane ns nf dipl diplp diplm cse fa csp csm, replace


** 04. Basic Demographics (Sex and Age/birth year) **

rename se sex
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex


ge birthyr = 1000 + ane
ge age=year-birthyr

lab var birthyr "Year of Birth"
lab var age "age"


** 05. Siblings **

rename ns nsis
lab var nsis "number of sisters"

rename nf nbro
lab var nbro "number of brothers"

ge nsibs=nsis+nbro
lab var nsibs "number of siblings"


** 06. Own education **

rename dipl educ_cat
replace educ_cat="1" if educ_cat=="AA"
replace educ_cat="2" if educ_cat=="AB"
replace educ_cat="3" if educ_cat=="BA"
replace educ_cat="4" if educ_cat=="BB"
replace educ_cat="5" if educ_cat=="BC"
replace educ_cat="6" if educ_cat=="BD"
replace educ_cat="7" if educ_cat=="CA"
replace educ_cat="8" if educ_cat=="CB"
replace educ_cat="9" if educ_cat=="CC"
replace educ_cat="10" if educ_cat=="CD"
replace educ_cat="11" if educ_cat=="DA"
replace educ_cat="12" if educ_cat=="DB"
replace educ_cat="13" if educ_cat=="EA"
replace educ_cat="14" if educ_cat=="FA"
replace educ_cat="15" if educ_cat=="GA"
replace educ_cat="16" if educ_cat=="GB"

destring educ_cat, replace

**label education values**

#delimit ;
lab def educ_cat 
1 "agregation, CAPES, diplome de grande ecole, doctorat" // doctor, 20, 844
2 "licence, maitrise" // bachelor, master, 15-17, 645,747 
3 "brevet de technician superieur (BTS), diplome universitaire de technologie (DUT)" // diploma in technological studies, diploma of advanced technician, arts trades, 14, 554
4 "diplome du 1er cycle du superieur" // 1st cycle univ education, 14, 554 
5 "diplome paramedical ou social avec baccalaureat" // qual in health and social services, 14-15, 554
6 "diplome paramedical ou social sans baccalaureat" // qual in social services, 13, 354
7 "baccalaureat general, avec diplome technique" // general and technological bacaalaureat, 12, 344 
8 "baccalaureat general, sans diplome technique" // general baccalaureat, 12, 344
9 "baccalaureat de technicien" // vocational baccalaureat, 12, 354
10 "brevet d'enseignement industriel (BEI), commercial (BEC), hotelier (BEH), social (BES), agricole (BEA), brevet professionnel" // vocational qual, 13, 353
11 "certificat d'aptitude professionnelle (CAP) avec BEPC" // secondary vocational, 11, 353
12 "certificat d'aptitude professionnelle (CAP) sans BEPC" // secondary vocational, 11, 353
13 "brevet d'etudes du 1er cycle (BEPC) sans CAP" // secondary educ (first cycle), 9, 244
14 "certificat d'etudes primaires"  // primary education, 5, 100
15 "aucun diplome apres etudes" // primary education, 5, 100
16 "pas d'etudes initiales";
#delimit cr
lab val educ_cat educ_cat
lab var educ_cat "highest level of education completed"


** 07. Parents' education: Father and/or Mother **

rename diplp faeduc_cat
rename diplm moeduc_cat

#delimit ;
lab def pareduc 
20 "etudes superieures" // higher education, 15-20 (probably 16 on average?), 600-800
21 "brevet de technician superieur (BTS), diplome universitaire de technologie (DUT)" // 14, 554
22 "diplome paramedical ou social avec baccalaureat" // 14-15, 554
23 "diplome paramedical ou social sans baccalaureat" // 13, 354
30 "baccalaureat general (A-D), et diplome technique" // 12, 344
31 "baccalaureat general (A-D)" // 12, 344
32 "baccalaureat technique (F-H)" // 12, 354
33 "brevet d'enseignement industriel (BEI), commercial (BEC), hotelier (BEH), social (BES), agricole (BEA), brevet professionnel" // 13, 353
40 "certificat d'aptitude professionnelle (CAP), brevet d'etudes professionnelles (BEP) avec BEPC" // 11, 353
41 "certificat d'aptitude professionnelle (CAP), brevet d'etudes professionnelles (BEP) sans BEPC" // 11, 353
50 "brevet d'etudes du 1er cycle (BEPC) sans CAP" // 9, 244
60 "certificat d'etudes primaires" // 5, 100
70 "aucun diplome declare (no diploma declared)"; // 9, 244
#delimit cr
lab val faeduc_cat moeduc_cat pareduc  
lab var faeduc_cat "father's education level"
lab var moeduc_cat "mother's education level"


** Create Years of Education Variables for respondent and parents**

ge educ_yrs = .
replace educ_yrs = 20 if educ_cat == 1
replace educ_yrs = 16 if educ_cat == 2
replace educ_yrs = 14 if educ_cat == 3
replace educ_yrs = 14 if educ_cat == 4
replace educ_yrs = 14.5 if educ_cat == 5
replace educ_yrs = 13 if educ_cat == 6
replace educ_yrs = 12 if educ_cat == 7
replace educ_yrs = 12 if educ_cat == 8
replace educ_yrs = 12 if educ_cat == 9
replace educ_yrs = 13 if educ_cat == 10
replace educ_yrs = 11 if educ_cat == 11
replace educ_yrs = 11 if educ_cat == 12
replace educ_yrs = 9 if educ_cat == 13
replace educ_yrs = 9 if educ_cat == 14
replace educ_yrs = 9 if educ_cat == 15
replace educ_yrs = 0 if educ_cat == 16


lab var educ_yrs "Years of education - respondent"

ge faeduc_yrs = .
replace faeduc_yrs = 16 if faeduc_cat == 20
replace faeduc_yrs = 14 if faeduc_cat == 21
replace faeduc_yrs = 14 if faeduc_cat == 22
replace faeduc_yrs = 13 if faeduc_cat == 23
replace faeduc_yrs = 12 if faeduc_cat == 30
replace faeduc_yrs = 12 if faeduc_cat == 31
replace faeduc_yrs = 12 if faeduc_cat == 32
replace faeduc_yrs = 13 if faeduc_cat == 33
replace faeduc_yrs = 11 if faeduc_cat == 40
replace faeduc_yrs = 11 if faeduc_cat == 41
replace faeduc_yrs = 9 if faeduc_cat == 50
replace faeduc_yrs = 9 if faeduc_cat == 60
replace faeduc_yrs = 9 if faeduc_cat == 70

lab var faeduc_yrs "Years of education - father"

ge moeduc_yrs = .
replace moeduc_yrs = 16 if moeduc_cat == 20
replace moeduc_yrs = 14 if moeduc_cat == 21
replace moeduc_yrs = 14 if moeduc_cat == 22
replace moeduc_yrs = 13 if moeduc_cat == 23
replace moeduc_yrs = 12 if moeduc_cat == 30
replace moeduc_yrs = 12 if moeduc_cat == 31
replace moeduc_yrs = 12 if moeduc_cat == 32
replace moeduc_yrs = 13 if moeduc_cat == 33
replace moeduc_yrs = 11 if moeduc_cat == 40
replace moeduc_yrs = 11 if moeduc_cat == 41
replace moeduc_yrs = 9 if moeduc_cat == 50
replace moeduc_yrs = 9 if moeduc_cat == 60
replace moeduc_yrs = 9 if moeduc_cat == 70

lab var moeduc_yrs "Years of education - mother"


** 08. Own occupation **

rename cse occ_code

rename fa emp_stat

lab var occ_code "Occupational Category"

lab var emp_stat "employment status"

*label occupation values*

#delimit ;
lab def emp_statL 

1 "Exercises a profession"
2 "Unemployed (registered or not with the ANPE)"
3 "Student, pupil, trainee, unpaid internship"
4 "Military contingent"
5 "Retired (former employee) or pre-retired"
6 "Withdrawn from business (former farmer, former craftsman, former merchant)"
7 "Homemaker (including parental leave)"
8 "Other inactive (including persons receiving only a reversion pension and Disabled persons)";

lab def occ_codeL 

1 "Unknown"
2 "Smallholder farmer"
3 "Farmer on medium holding"
4 "Farmer on large holding"
5 "Artisan"
6 "Merchant and related"
7 "Entrepreneur with 10 or more employees"
8 "Professional Occupation"
9 "Public Service Framework"
10 "Professor, scientific profession"
11 "Information, Arts and Entertainment Occupations"
12 "Corporate Administrative and Business Framework"
13 "Engineer and technical manager"
14 "School teacher, teacher and related occupations"
15 "Intermediate health and social work worker"
16 "Clergy, Religious"
17 "Administrative administrative intermediary of the civil service"
18 "Administrative and business intermediary business"
19 "Technician"
20 "Foreman, supervisor"
21 "Civilian Employee and Public Service Officer"
22 "Supervisory officer"
23 "Administrative clerk"
24 "Business Employee"
25 "Direct Services Personnel"
26 "Qualified Industrial Worker"
27 "Skilled craftsman"
28 "Driver"
29 "Qualified Worker in Handling, Warehousing and Transportation"
30 "Unskilled Industrial Worker"
31 "Unskilled craftsman"
32 "Agricultural and related worker";
#delimit cr

lab val emp_stat emp_statL

lab val occ_code occ_codeL


** 09. Parents' occupation **

rename csp faocc_code

rename csm moocc_code

lab var faocc_code "Father's Occupational Category"

lab var moocc_code "Mother's Occupational Category"

*label parental occupation values*

lab val faocc_code occ_codeL

lab val moocc_code occ_codeL

** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** FRENCH 1985 TRAINING AND QUALIFYING SURVEY PROFESSIONAL

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs, d

** R's Own Education **
tab1 educ_cat educ_yrs

** Parental Education **
tab1 faeduc_cat moeduc_cat faeduc_yrs moeduc_yrs

** R's Own Occupation **
tab1 occ_code emp_stat

** Parent's Occupation **
tab1 faocc_code moocc_code

log close

** 11. Keep the identified variables only

keep year country pid sex age birthyr ///
	 nsibs ///
	 educ_cat educ_yrs faeduc_cat moeduc_cat faeduc_yrs moeduc_yrs ///
	 occ_code emp_stat faocc_code moocc_code


** 12. Create ISCED Education Variables **

ge educ_ISCED = .
replace educ_ISCED = 844 if educ_cat == 1
replace educ_ISCED = 645 if educ_cat == 2
replace educ_ISCED = 554 if educ_cat == 3
replace educ_ISCED = 554 if educ_cat == 4
replace educ_ISCED = 554 if educ_cat == 5
replace educ_ISCED = 354 if educ_cat == 6
replace educ_ISCED = 344 if educ_cat == 7
replace educ_ISCED = 344 if educ_cat == 8
replace educ_ISCED = 354 if educ_cat == 9
replace educ_ISCED = 353 if educ_cat == 10
replace educ_ISCED = 353 if educ_cat == 11
replace educ_ISCED = 353 if educ_cat == 12
replace educ_ISCED = 244 if educ_cat == 13
replace educ_ISCED = 200 if educ_cat == 14
replace educ_ISCED = 200 if educ_cat == 15
replace educ_ISCED = 0 if educ_cat == 16

ge faeduc_ISCED = .
replace faeduc_ISCED = 600 if faeduc_cat == 20
replace faeduc_ISCED = 554 if faeduc_cat == 21
replace faeduc_ISCED = 554 if faeduc_cat == 22
replace faeduc_ISCED = 354 if faeduc_cat == 23
replace faeduc_ISCED = 344 if faeduc_cat == 30
replace faeduc_ISCED = 344 if faeduc_cat == 31
replace faeduc_ISCED = 354 if faeduc_cat == 32
replace faeduc_ISCED = 353 if faeduc_cat == 33
replace faeduc_ISCED = 353 if faeduc_cat == 40
replace faeduc_ISCED = 353 if faeduc_cat == 41
replace faeduc_ISCED = 244 if faeduc_cat == 50
replace faeduc_ISCED = 200 if faeduc_cat == 60
replace faeduc_ISCED = 200 if faeduc_cat == 70

ge moeduc_ISCED = .
replace moeduc_ISCED = 600 if moeduc_cat == 20
replace moeduc_ISCED = 554 if moeduc_cat == 21
replace moeduc_ISCED = 554 if moeduc_cat == 22
replace moeduc_ISCED = 354 if moeduc_cat == 23
replace moeduc_ISCED = 344 if moeduc_cat == 30
replace moeduc_ISCED = 344 if moeduc_cat == 31
replace moeduc_ISCED = 354 if moeduc_cat == 32
replace moeduc_ISCED = 353 if moeduc_cat == 33
replace moeduc_ISCED = 353 if moeduc_cat == 40
replace moeduc_ISCED = 353 if moeduc_cat == 41
replace moeduc_ISCED = 244 if moeduc_cat == 50
replace moeduc_ISCED = 200 if moeduc_cat == 60
replace moeduc_ISCED = 200 if moeduc_cat == 70


** 13. Save the Data File **

saveold /*insert you work directory here*/, replace

